package com.ruoyi.web.controller.warning;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.warning.domain.entity.Area;
import com.ruoyi.warning.domain.query.AreaQuery;
import com.ruoyi.warning.service.IAreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 区域表 前端控制器
 * </p>
 *
 * @author chenhc
 * @since 2025-02-25
 */
@RestController
@RequestMapping("/area")
@Api(tags = "厂区区域", description = "用于处理厂区区域相关操作的控制器")
public class AreaController {
    @Resource
    private IAreaService iAreaService;
    @ApiOperation("分页")
    @Log(title = "分页查询区域", businessType = BusinessType.SELECT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/page")
    public R<TableDataInfo> page(AreaQuery query)
    {
        return R.ok(iAreaService.getAreaPage(query));
    }

    @ApiOperation("列表")
    @Log(title = "查询区域列表", businessType = BusinessType.SELECT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/list")
    public R list(AreaQuery query)
    {
        return R.ok(iAreaService.getAreaList(query));
    }
    @Anonymous
    @ApiOperation("树")
    @Log(title = "查询区域树", businessType = BusinessType.SELECT)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/tree")
    public R tree(AreaQuery query){
        return R.ok(iAreaService.getAreaTree(query));
    }

    @ApiOperation("刷新")
    @Log(title = "刷新", businessType = BusinessType.OTHER)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/refresh")
    public R refresh()
    {
        return R.ok(iAreaService.refresh());
    }

    @ApiOperation("修改使用状态")
    @Log(title = "修改使用状态", businessType = BusinessType.UPDATE)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/updateUsed/{id}")
    public R updateUsed(@PathVariable String id)
    {
        return R.ok(iAreaService.updateUsed(id));
    }

    @ApiOperation("新增或修改厂区")
    @Log(title = "新增或修改厂区", businessType = BusinessType.UPDATE)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @PostMapping(value = "/saveOrUpdateArea")
    public R saveOrUpdateArea(@RequestBody Area area)
    {
        return R.ok(iAreaService.saveOrUpdate(area));
    }

    @ApiOperation("查看详情")
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @GetMapping(value = "/detail/{id}")
    public R detail(@PathVariable String id)
    {
        return R.ok(iAreaService.getById(id));
    }

    @ApiOperation("删除")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    //@PreAuthorize("@ss.hasPermi('system:config:export')")
    @DeleteMapping(value = "/delete/{id}")
    public R delete(@PathVariable String id)
    {
        return R.ok(iAreaService.removeById(id));
    }
}
